<template>
  <slot>
    <component v-if="app" :is="app"></component>
  </slot>
</template>
<script>
import BaseComponent from "./BaseComponent.vue";
window.BaseComponent = BaseComponent;
const Application = {
  name: "Application",
  props: ["session", "noAuth", "apiDoc", "app"],
  extends: BaseComponent,
  components: { BaseComponent },
  data() {
    window.a = this;
    return {};
  },
  computed: {},
  provide() {
    // this.$g.toast.ctx = ElMessage;
    return {
      $g: this.$g,
      $app: this
    };
  },
  watch: {
    "$g.session.store.data": {
      handler(fresh, old) {
        console.log("[watch][$g.session.data]", fresh, old, this);
        this.$g.session.routeAuth(this.$route, null, this.$router);
      },
      deep: false
      // immediate: true
    },
    $route: {
      handler(fresh, old) {
        this.$g.session.routeAuth(fresh, old, this.$router);
      }
      //  deep: false
      // immediate: true
    }
  },

  created() {
    // setTimeout(() => {
    //   this.$g.toast(11, "error");
    // }, 100);
    // let sessionData = {
    //   user: { name: "admin" },
    //   permissions: [
    //     {
    //       code: "user",
    //       path: "/user",
    //       children: [{ code: "user.get", path: "/user/get" }]
    //     },
    //     {
    //       code: "home",
    //       path: "/home",
    //       children: [{ code: "home.get", path: "/home/get" }]
    //     }
    //   ]
    // };
    // this.$g.session.store.enbled = false; //关闭鉴权
    // setTimeout(() => {
    //   this.$g.session(sessionData);
    // }, 2000);
    // console.log("created", this);
    // this.$g
    //   .ajax(
    //     { url: "/api/getsession" },
    //     {
    //       cancel(cancel) {
    //         console.log(cancel);
    //         cancel(111, 222);
    //       }
    //     }
    //   )
    //   .then((res) => console.log(res));
  },
  methods: {}
};
export default Application;
import components from "../components/index.js";
Application.install = (app) => {
  app.component(Application.name, Application);
  app.use(components);
  let msgTarget = null;
  app.config.globalProperties.$msg = (message, type, notOnly) => {
    !notOnly && msgTarget && msgTarget.close();
    let $message = app.config.globalProperties.$message;
    msgTarget = $message && $message({ showClose: true, message: message, type: type || "info" });
    return msgTarget;
  };
};
</script>
